//
//  HEProxyPayCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2021/5/8.
//  Copyright © 2021 honglutec. All rights reserved.
//

#import "HEProxyPayCell.h"
#import "HESysMsgModel.h"

@interface HEProxyPayCell()
 
@property (nonatomic, strong) UILabel *titleLb;
@property (nonatomic, strong) UILabel *timeLb;
@property (nonatomic, strong) UILabel *contentLb;

@property (nonatomic, strong) UIImageView *goodsimgView;
@property (nonatomic, strong) UILabel *nameLb;
@property (nonatomic, strong) UILabel *subTitleLb;

@end

@implementation HEProxyPayCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.contentView.backgroundColor = CLightGrayColor;
     
        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    UIView *warp = [UIView new];
    warp.backgroundColor = KWhiteColor;
    [self.contentView addSubview:warp];
 
    warp.layer.shadowColor = [UIColor colorWithRed:13/255.0 green:98/255.0 blue:218/255.0 alpha:0.08].CGColor;
    warp.layer.shadowOffset = CGSizeMake(0,5);
    warp.layer.shadowOpacity = 1;
    warp.layer.shadowRadius = 6;
    warp.layer.cornerRadius = 8;
 
    [warp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(0);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.bottom.equalTo(self.contentView).mas_offset(-15);
    }];
    
    
    // head
    UIView *blueLine = [UIView new];
    blueLine.backgroundColor = CNavBgColor;
    [warp addSubview:blueLine];
    
    _titleLb = [UILabel new];
    _titleLb.text = @"";
    _titleLb.font = DYBlodFont(18);
    _titleLb.numberOfLines = 0;
    [warp addSubview:_titleLb];
 
    
    UIView *headBottomLine = [UIView new];
    headBottomLine.backgroundColor = CSplitLineColor;
    [warp addSubview: headBottomLine];
    
    
    _timeLb = [UILabel new];
    _timeLb.text = @"";
    _timeLb.font = DYFont(16);
    _timeLb.textColor = CNavDargGrayColor;
    [warp addSubview: _timeLb];
 
    
    // middle
    // 头像
    _goodsimgView = [UIImageView new];
    _goodsimgView.image = IMAGE_NAMED(@"noImage");
    _goodsimgView.contentMode = UIViewContentModeScaleAspectFill;
    [warp addSubview:_goodsimgView];

    // 姓名
    _nameLb = [UILabel new];
    _nameLb.text = @"";
    _nameLb.font = DYBlodFont(17);
    _nameLb.numberOfLines = 0;
    [warp addSubview:_nameLb];
    
    
    // 子标题
    _subTitleLb = [UILabel new];
    _subTitleLb.text = @"";
    _subTitleLb.font = DYFont(16);
    _subTitleLb.textColor = CNavLightBlackColor;
    _subTitleLb.numberOfLines = 0;
    [warp addSubview:_subTitleLb];
    
    
    // footer
    _contentLb = [UILabel new];
    _contentLb.text = @"若您对本次代付有所疑问，您可点击进入查看订单，与请求代付人联系确认";
    _contentLb.font = DYFont(15);
    _contentLb.textColor = CNavDargGrayColor;
    _contentLb.numberOfLines = 0;
    [warp addSubview: _contentLb];
    
    
    [blueLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_titleLb);
        make.left.equalTo(warp).offset(10);
        make.width.offset(3);
        make.height.offset(20);
    }];
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).offset(15);
        make.left.equalTo(blueLine.mas_right).offset(10);
        make.right.equalTo(_timeLb.mas_left).offset(-10);
    }];

    [_timeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).offset(15);
        make.right.equalTo(warp).offset(-15);
    }];
    [_timeLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
    
  
    [_goodsimgView mas_makeConstraints:^(MASConstraintMaker *make) {
       make.top.equalTo(_titleLb.mas_bottom).mas_offset(15);
       make.left.equalTo(warp).mas_offset(15);
       make.width.height.mas_offset(50);
    }];
    _goodsimgView.layer.masksToBounds = YES;
    _goodsimgView.layer.cornerRadius = 25;
 
    [_nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(15);
        make.left.equalTo(_goodsimgView.mas_right).offset(15);
        make.right.equalTo(warp).mas_offset(-10);
    }];
    [_nameLb setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
    
    [_subTitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nameLb.mas_bottom).mas_offset(10);
        make.left.equalTo(_goodsimgView.mas_right).offset(15);
        make.right.equalTo(warp).mas_offset(-10);
    }];
    [_subTitleLb setContentCompressionResistancePriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
    
      
    //  footer
    UIView *footerTopLine = [UIView new];
    footerTopLine.backgroundColor = CSplitLineColor;
    [warp addSubview: footerTopLine];
    [footerTopLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_subTitleLb.mas_bottom).offset(10);
        make.left.equalTo(warp).offset(10);
        make.right.equalTo(warp).offset(-10);
        make.height.offset(1);
    }];
    
    [_contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(footerTopLine.mas_bottom).offset(15);
        make.left.equalTo(warp).offset(15);
        make.right.equalTo(warp).offset(-15);
        make.bottom.equalTo(warp).offset(-15);
    }];
    
//
//    UILabel *checkLb = [UILabel new];
//    checkLb.text = @"立即查看";
//    checkLb.font = DYFont(16);
//    [warp addSubview: checkLb];
//
//    [checkLb mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(footerTopLine.mas_bottom).offset(15);
//        make.left.equalTo(warp).offset(10);
//        make.bottom.equalTo(warp.mas_bottom).offset(-15);
//    }];
//
//    UIImageView *_arrowView = [UIImageView new];
//    _arrowView.contentMode = UIViewContentModeScaleAspectFill;
//    _arrowView.image = IMAGE_NAMED(@"go_gray");
//    [warp addSubview:_arrowView];
//
//    [_arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(checkLb);
//        make.right.equalTo(warp).mas_offset(-15);
//        make.width.mas_offset(8);
//        make.height.mas_offset(12);
//    }];
}


- (void)configCellWithModel:(HESysMsgModel *)model {
 
    _titleLb.text = model.Ksystem_typeName;
    _timeLb.text = model.Kcreate_date;
    
    HEProxyPayInfoModel *info = (HEProxyPayInfoModel *)model.params;
    [_goodsimgView sd_setImageWithURL:[NSURL URLWithString:info.old_info.avatar] placeholderImage:IMAGE_NAMED(@"defualt_icon")];

    _nameLb.text = info.old_info.KnameRel;
    _subTitleLb.text = info.title;
    
    [self showbadge: !model.is_read];
}

- (void)showbadge:(BOOL)show {
  
    if (show) {
        [_timeLb pp_showBadge];
  
        _timeLb.badgeView.font = DYBlodFont(14);
 
        [_timeLb pp_addDotWithColor: CPriceColor];
        [_timeLb pp_setBadgeHeight: 12];
        [_timeLb pp_moveBadgeWithX: 5 Y: 0];
    }else {
        [_timeLb pp_hiddenBadge];
    }
}

@end
